package com.varian.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.varian.service.annotation.Resubmit;
import com.varian.service.web.BaseController;
import com.varian.system.dto.SysBizExceptionDTO;
import com.varian.system.dto.SysBizExceptionPageDTO;
import com.varian.system.service.ISysBizExceptionService;
import com.varian.system.vo.SysBizExceptionVO;
import com.varian.tool.result.IR;
import com.varian.tool.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ben
 * @since 2024/9/24
 */
@Resubmit
@RestController
@Tag(name = "业务异常控制层")
@RequestMapping("/biz-exception")
public class SysBizExceptionController extends BaseController<ISysBizExceptionService> {

    @Operation(summary = "业务异常分页")
    @GetMapping("page")
    @PreAuthorize("hasAuthority('biz-exception:page')")
    public R<Page<SysBizExceptionVO>> page(@Validated SysBizExceptionPageDTO dto){
        return R.data(baseService.page(dto));
    }
    
    @Operation(summary = "业务异常详情")
    @GetMapping("{id:\\d+}")
    @PreAuthorize("hasAuthority('biz-exception:detail')")
    public R<SysBizExceptionVO> detail(@PathVariable("id") Long id){
        return R.data(baseService.detail(id));
    }
    
    @Operation(summary = "业务异常新增")
    @PostMapping
    @PreAuthorize("hasAuthority('biz-exception:add')")
    public IR add(@Validated @RequestBody SysBizExceptionDTO dto){
        return R.status(baseService.add(dto));
    }
    
    @Operation(summary = "业务异常修改")
    @PutMapping("{id:\\d+}")
    @PreAuthorize("hasAuthority('biz-exception:modify')")
    public IR modify(@PathVariable("id") Long id, @Validated @RequestBody SysBizExceptionDTO dto){
        return R.status(baseService.modify(id, dto));
    }
    
    @Operation(summary = "业务异常删除")
    @DeleteMapping("{id:\\d+}")
    @PreAuthorize("hasAuthority('biz-exception:delete')")
    public IR delete(@PathVariable("id") Long id){
        return R.status(baseService.delete(id));
    }
}
